#ifndef SNAKE_GAME_H
#define SNAKE_GAME_H

#include "common/point.h"
#include "snake/snake.h"

const int SNAKE_GAME_WIDTH = 24;
const int SNAKE_GAME_HEIGHT = 18;

class SnakeGame {

public:
    Snake snake;
    char inhibitTailStep;
    unsigned occupiedCells;

    SnakeGame();
    SnakeGame(int width, int height, int foodCount);
    ~SnakeGame();

    GameUnit* getCell(Point& point);
    void setCell(Point& point, GameUnit* unit);
    bool isCellsFull();

    void newFood();

    void redir(Direction& dir);
    void step();
    void init();
    void draw(SDL_Renderer *renderer, ResourceManager& resManager);
    int getWindowsWidth();
    int getWindowsHeight();

private:
    int unitWidth;
    int width;
    int height;

    int foodCount;
    GameUnit** matrix;

    bool isValidPoint(Point& point);
    void wrapAround(int *val, int max);
    void resetMatrix();
    void removeTail();
    void moveTo(Point& point);
    void moveHeadForward();
    Point getNextPos();
};

#endif
